import React from "react";
import Grid from "./grid";
import _ from 'lodash'
import {render as vjsonRender, renderItems} from "../../factory";
import {IGridCellRenderParam} from "./grid_type";

interface CellVJsonProp extends IGridCellRenderParam {
    $context: any

    colDef: {
        /**
         * 渲染函数
         */
        render: (param: IGridCellRenderParam) => any
    }

    grid: Grid
}

interface CellVJsonState {
}

export default class CellVJsonRenderer extends React.Component<CellVJsonProp, CellVJsonState> {

    // @ts-ignore
    render() {
        // 计算 vjson
        // @ts-ignore
        const vjson = this.props.colDef.render(this.props)
        if (_.isArray(vjson)) {
            return (
                <>
                    {
                        ...renderItems(this.props.grid, vjson, {grid: this.props.grid})
                    }
                </>
            )
        }
        return vjsonRender(this.props.grid, vjson, {grid: this.props.grid})
    }
}
